home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST7-5.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  81 lines

  1. ;
  2. ; *** Listing 7-5 ***
  3. ;
  4. ; Adds one far array to another far array as only assembler
  5. ; can, loading the two far pointers once and keeping them in
  6. ; the registers during the entire loop for speed.
  7. ;
  8.     jmp    Skip
  9. ;
  10. ARRAY_LENGTH    equ    1000
  11. Array1    db    ARRAY_LENGTH dup (1)
  12. Array2    db    ARRAY_LENGTH dup (2)
  13. ;
  14. ; Adds one byte-sized array to another byte-sized array.
  15. ; C-callable.
  16. ;
  17. ; Input: parameters on stack as in AddArraysParms
  18. ;
  19. ; Output: none
  20. ;
  21. ; Registers altered: AL, BX, CX, DX, ES
  22. ;
  23. AddArraysParms    struc
  24.     dw    ?    ;pushed BP
  25.     dw    ?    ;return address
  26. FarPtr1    dd    ?    ;pointer to array to be added to
  27. FarPtr2    dd    ?    ;pointer to array to add to the
  28.             ; other array
  29. AddArraysLength    dw ?    ;# of bytes to add
  30. AddArraysParms    ends
  31. ;
  32. AddArrays    proc    near
  33.     push    bp        ;save caller's BP
  34.     mov    bp,sp        ;point to stack frame
  35.     push    si        ;save registers used by many
  36.     push    di        ; C compilers for register
  37.                 ; variables
  38.     mov    cx,[bp+AddArraysLength]
  39.                 ;get the length to add
  40.     les    si,[bp+FarPtr2]    ;point to the array to add
  41.                 ; from
  42.     mov    dx,es        ;set aside the segment
  43.     les    bx,[bp+FarPtr1]    ;point to the array to add
  44.                 ; to
  45.     mov    di,es        ;set aside the segment
  46. AddArraysLoop:
  47.     mov    es,dx        ;point ES:SI to the next
  48.                 ; byte of the array to add
  49.                 ; from
  50.     mov    al,es:[si]    ;get the array element to
  51.                 ; add
  52.     inc    si        ;point to the next byte of
  53.                 ; the array to add from
  54.     mov    es,di        ;point ES:BX to the next
  55.                 ; byte of the array to add
  56.                 ; to
  57.     add    es:[bx],al    ;add to the array
  58.     inc    bx        ;point to the next byte of
  59.                 ; the array to add to
  60.     loop    AddArraysLoop
  61.     pop    di        ;restore registers used by
  62.     pop    si        ; many C compilers for
  63.                 ; register variables
  64.     pop    bp        ;restore caller's BP
  65.     ret
  66. AddArrays    endp
  67. ;
  68. Skip:
  69.     call    ZTimerOn
  70.     mov    ax,ARRAY_LENGTH
  71.     push    ax    ;pass the length to add
  72.     push    ds    ;pass segment of Array2
  73.     mov    ax,offset Array2
  74.     push    ax    ;pass offset of Array2
  75.     push    ds    ;pass segment of Array1
  76.     mov    ax,offset Array1
  77.     push    ax    ;pass offset of Array1
  78.     call    AddArrays
  79.     add    sp,10    ;clear the parameters
  80.     call    ZTimerOff
  81.